﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using OnTheWay.Functions;
using Models;
using LocalService;

namespace PcBackgroundMgr.Functions
{
    /// <summary>
    /// ExhibitUnitList.xaml 的交互逻辑
    /// </summary>
    public partial class ExhibitUnitList : ExhibitUnitListBase
    {
        private bool IsMax = false;

        public ExhibitUnitList()
        {
            InitializeComponent();
        }

        protected override void OnCommandAdd(object obj)
        {
            ExhibitUnitModelCtrl fun = new ExhibitUnitModelCtrl();
            fun.SetExhibit(Model);
            fun.OperateMode = FunctionCtrlModelBase.OperateModeEnum.Add;
            fun.SetOnAdded(x => Items.Insert(0, x));
            fun.Model = fun.OnInitializeModel(null);
            if (fun.Model != null && Model != null)
            {
                fun.Model.Name = Model.Name;
                fun.Model.MooMaUrl = "";
                fun.Model.ExhibitID = Model.ID;
            }

            FrameworkElement control = this;
            do
            {
                control = control.Parent as FrameworkElement;
            } while (!(control is FunctionCtrlModelBase) && control != null);
            if (control is FunctionCtrlModelBase)
            {
                FunctionCtrlModelBase patent = control as FunctionCtrlModelBase;
                patent.IFunPanel.FunctionStackPut(fun);
            }
        }

        protected override void OnCommandDelete(object obj)
        {
            base.OnCommandDelete(obj);
        }

        protected override void OnCommandMinSize(object obj)
        {
            //base.OnCommandMinSize(obj);
            if (IsMax)
            {
            }
            else
            {

            }
        }
    }

    [DesignTimeVisible(false)]
    public partial class ExhibitUnitListBase : FunctionCtrlList<ExhibitUnit>
    {
        public Exhibit Model
        {
            get { return (Exhibit)GetValue(ModelProperty); }
            set { SetValue(ModelProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Model.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ModelProperty =
            DependencyProperty.Register("Model", typeof(Exhibit),typeof(ExhibitUnitListBase),
            new FrameworkPropertyMetadata(null, OnModelPropertyChanged));

        public static void OnModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ExhibitUnitListBase ctrl = d as ExhibitUnitListBase;
            Exhibit model = e.NewValue as Exhibit;
            if (model != null)
            {
                ctrl.mDomain = LocalFactory.ExhibitUnitLocal;
                ctrl.mSqlWhere = " where ExhibitID='" + model.ID + "'";
                ctrl.OnCommandRefresh(null);
            }
        }



        public ICommand CommandMax
        {
            get { return (ICommand)GetValue(CommandMaxProperty); }
            set { SetValue(CommandMaxProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CommandMax.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CommandMaxProperty =
            DependencyProperty.Register("CommandMax", typeof(ICommand),
            typeof(ExhibitUnitListBase), new UIPropertyMetadata(null));

        
    }
}
